package com.eurasia.assignment.controller;

import com.eurasia.assignment.controller.dto.CreateCodeSubmissionResponse;
import com.eurasia.assignment.controller.dto.ProblemQuery;
import com.eurasia.assignment.domain.hoj.CodeInfo;
import com.eurasia.assignment.service.HOJFullCaseJudgementService;
import com.eurasia.assignment.service.HOJResourceService;
import com.eurasia.assignment.service.port.out.dto.ConclusionJudgementResult;
import com.eurasia.assignment.service.port.out.dto.CreateFullCaseJudgementRequest;
import com.eurasia.assignment.service.port.out.dto.CreateFullCaseJudgementResponse;
import com.eurasia.assignment.service.port.out.dto.HOJResource;
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.RequiredArgsConstructor;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/hoj")
@RequiredArgsConstructor
public class HOJResourceController {
    private final HOJResourceService service;
    private final HOJFullCaseJudgementService fullCaseJudgementService;

    @GetMapping("problems")
    public ResponseEntity<String> getProblems(@SpringQueryMap ProblemQuery query) {
        return service.getProblems(query);
    }

    @GetMapping("problems/{id}")
    public ResponseEntity<String> getProblemDetail(@PathVariable String id) {
        return service.getProblemById(id);
    }

    @PostMapping("test-judgement")
    public ResponseEntity<CreateCodeSubmissionResponse> createCodeSubmission(@RequestBody CodeInfo request) throws JsonProcessingException {
        return service.createSingleCaseJudgement(request);
    }

    @GetMapping("test-judgement-result")
    public ResponseEntity<String> getTestJudgementResult(@RequestParam String testJudgeKey) {
        return service.getJudgementResult(testJudgeKey);
    }

    @PostMapping("full-case-judgements")
    public ResponseEntity<HOJResource<CreateFullCaseJudgementResponse>> getTestJudgementResult(@RequestBody CreateFullCaseJudgementRequest request) {
        return service.createFullCaseJudgement(request);
    }

    @GetMapping("full-case-judgement-result")
    public ResponseEntity<String> getFullCaseJudgementResult(@RequestParam Long submitId) {
        return fullCaseJudgementService.fetchFullCaseJudgementResult(submitId);
    }

    @GetMapping("full-case-judgement-detailed-result")
    public ResponseEntity<String> getFullCaseJudgementDetailedResult(@RequestParam Long submitId) {
        return fullCaseJudgementService.fetchFullCaseJudgementDetailedResult(submitId);
    }
}
